package com.richard.dev.common;

import com.richard.library.basic.provider.FileDownloadProvider;
import com.richard.library.basic.util.FileUtil;
import com.richard.library.http.download.FileDownloadRetrofitCallback;
import com.richard.library.http.download.FileDownloader;

import java.io.File;

/**
 * @author: Richard
 * @createDate: 2023/4/10 10:48
 * @version: 1.0
 * @description: android APP下载器提供者
 */
public class APKFileDownLoadProvider extends FileDownloadProvider {

    private final FileDownloader downloader = new FileDownloader();

    @Override
    public void startDownload(String downloadLink) {
        File apkFile = new File(FileUtil.getCacheDir() + "/" + System.currentTimeMillis() + ".apk");
        downloader.download(downloadLink, new FileDownloadRetrofitCallback(apkFile) {
            @Override
            public void onSuccess(File responseFile) {
                callback.onSuccess(responseFile);
            }

            @Override
            public void onFailure(String message, String code) {
                callback.onFailure(message, code);
            }
        });
    }

    @Override
    public void cancelDownload() {
        downloader.cancelDownload();
    }
}
